package com.lei.sqlGoodsJsp.service.Impl;

import java.util.List;

import com.lei.sqlGoodsJsp.dao.GoodsDao;
import com.lei.sqlGoodsJsp.dao.Impl.GoodsDaoImpl;
import com.lei.sqlGoodsJsp.entity.Goods;
import com.lei.sqlGoodsJsp.entity.Page;
import com.lei.sqlGoodsJsp.service.GoodsService;

public class GoodsServiceImpl implements GoodsService {
	private GoodsDao goodsDao = new GoodsDaoImpl();
// private ShopDao shopDao=new ShopDaoImpl();

	@Override
	public void add(Goods shopName) {
		goodsDao.add(shopName);

	}

	@Override
	public void delete(Long id) {
		goodsDao.delete(id);

	}

	@Override
	public void update(Goods id) {
		goodsDao.update(id);

	}

	@Override
	public List<Goods> list() {

		return goodsDao.listAll();
	}

	@Override
	public Goods getById(Long id) {
		return goodsDao.getById(id);
	}
	

	@Override
	public Page<Goods> page(int currentPage, int pageSize) {
		// 1、查询数据库有多少条数据
		int count = goodsDao.getCount();
		//2、根据分页条件得到limit  0(begin),  5(end)
		List<Goods> data = goodsDao.getPage(currentPage, pageSize);
		
//		GoodsPage page = new GoodsPage();
//		page.setCount(count);
//		page.setCurrentPage(currentPage);
//		page.setData(data);
		//11/5 = 2
		int totalPage = count/pageSize;
		totalPage += count%pageSize==0?0:1;
//		page.setTotalPage(totalPage);
		Page<Goods> page = new Page<>(count, totalPage, currentPage, data);
		return page;
	}

}
